package com.showde.shoppingmall.activity;

import com.showde.shoppingmall.R;
import com.showde.shoppingmall.business.InformationFetchBusiness.INFOMATION_TYPE;
import com.showde.shoppingmall.business.logic.CallbackData;
import com.showde.shoppingmall.business.logic.InformationFetchLogic;
import com.showde.shoppingmall.business.logic.UICallbackInterface;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.webkit.WebView;

public class CustomerServiceActivity extends BaseActivity {

	private static final int MSG_FETCH_SUCCESS = 0x10001;
	private static final int MSG_FETCH_FAIL = 0x10002;

	WebView webView;

	String data2Show;

	private Handler handler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case MSG_FETCH_SUCCESS:
				refresh();
				break;
			case MSG_FETCH_FAIL:
				refresh();
				break;

			default:
				break;
			}
			super.handleMessage(msg);
		}

	};

	@Override
	public void onClick(View v) {

	}

	@Override
	protected void initParam() {

	}

	@Override
	protected void initView() {
		setContentView(R.layout.activity_customerservice);
		webView = (WebView) findViewById(R.id.wv_customerservice);

	}

	@Override
	protected void onResume() {
		super.onResume();
		fetchData();
	}

	private void fetchData() {
		InformationFetchLogic.fetchGJPInfo(INFOMATION_TYPE.KHFW,
				new UICallbackInterface() {

					@Override
					public void onSuccess(CallbackData data) {
						data2Show = data.data.toString();
						handler.sendEmptyMessage(MSG_FETCH_SUCCESS);

					}

					@Override
					public void onError(String errorMsg) {
						data2Show = errorMsg;
						handler.sendEmptyMessage(MSG_FETCH_SUCCESS);
					}
				});
	}

	private void refresh() {
		webView.loadData(data2Show, "text/html", "utf-8");
	}

}
